package com.wang.ebook.adapter;

import java.util.ArrayList;

import com.wang.ebook.activity.R;
import com.wang.ebook.application.MyApplication;
import com.wang.ebook.bean.EBookBean;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter {
	private Context mContext;
	private MyApplication myApplication;
	public ArrayList<EBookBean> allEBookList = null;
	
	public GridViewAdapter(Context context ,MyApplication app){
		this.mContext = context;
		this.myApplication = app;
		allEBookList = app.allEBookList;
		Log.d("test","book size" + allEBookList.size());
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return allEBookList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.gridviewitem, null);
		}
		ImageView image = (ImageView)convertView.findViewById(R.id.imageView1);
		TextView tView = (TextView)convertView.findViewById(R.id.textView1);
		image.setImageBitmap(allEBookList.get(position).getSrcBitmap());
		tView.setText(allEBookList.get(position).getArtical_Title());
		return convertView;
	}

}
